package com.stu.exercise.controller;

import com.stu.exercise.entity.Equipment;
import com.stu.exercise.entity.R;
import com.stu.exercise.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/equipment")
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;

    @RequestMapping("/list")
    public R list(){
        List<Equipment> list = equipmentService.list();
        return R.success(list);
    }

    @RequestMapping("/add")
    public R add(@RequestBody Equipment equipment){
        boolean save = equipmentService.save(equipment);
        if (save){
            return R.success("添加成功", null);
        }
        return R.error(500, "添加失败");
    }

    @RequestMapping("/edit")
    public R edit(@RequestBody Equipment equipment){
        boolean update = equipmentService.updateById(equipment);
        if (update){
            return R.success("修改成功", null);
        }
        return R.error(500, "修改失败");
    }

}
